/**
 * 
 */
package com.et114.modules.extend.acegi;

import org.acegisecurity.AuthenticationException;
import org.acegisecurity.allways.IUserDetailsProvider;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

/*
 * @author guanhw
 */
public class AwDaoCasAuthoritiesPopulator implements AwCasAuthoritiesPopulator , InitializingBean  {
    //~ Instance fields ================================================================================================
	private IUserDetailsProvider userDetailsProvider ;
    private UserDetailsService userDetailsService;

    
	public AwDaoCasAuthoritiesPopulator ( ) {
		// TODO Auto-generated constructor stub
	}

	public UserDetails getUserDetailsDb ( String casUserId )
			throws AuthenticationException {
		// TODO Auto-generated method stub
		return this.userDetailsService.loadUserByUsername(casUserId);
	}

	public UserDetails getUserDetails ( String casUserId )
			throws AuthenticationException {
		// TODO Auto-generated method stub
		return userDetailsProvider.getUserDetailsByUserId ( casUserId ) ;
	}

	public void afterPropertiesSet ( ) throws Exception {
		// TODO Auto-generated method stub
        //Assert.notNull(this.userDetailsService, "A UserDetailsService must be set");
        Assert.state( !( userDetailsService == null &&  userDetailsProvider == null  ), ".userDetailsProvider , userDetailsService 必须设置一个！" );
		
	}

	public IUserDetailsProvider getUserDetailsProvider ( ) {
		return userDetailsProvider;
	}

	public void setUserDetailsProvider ( IUserDetailsProvider userDetailsProvider ) {
		this.userDetailsProvider = userDetailsProvider;
	}

	public UserDetailsService getUserDetailsService ( ) {
		return userDetailsService;
	}

	public void setUserDetailsService ( UserDetailsService userDetailsService ) {
		this.userDetailsService = userDetailsService;
	}
	
}
